package DataLayer.Model;

import java.util.ArrayList;

/**
 * keeps info about: DelOrdre.
 * 
 * @author Gruppe 4 - Dennis Biil, Brian Smed, Kristian Henriksen og Anders Engbo
 * @version 1.0
 */
public class DelOrdre
{
	private int delordreId;
	private int antal;
	private Produkt p;
	private Service s;
	private ArrayList<EkstraService> esList;

	/**
	 * Constructor
	 */
	public DelOrdre(
			int antal, Produkt p, Service s, ArrayList<EkstraService> esList)
	{
		this.antal = antal;
		this.p = p;
		this.s = s;
		this.esList = esList;
	}

	/**
	 * Empty constructor
	 */
	public DelOrdre()
	{
		this.delordreId = -1;
		this.antal = 0;
		this.p = null;
		this.s = null;
		this.esList = new ArrayList<EkstraService>();
	}

	/**
	 * Set and get methods
	 */
	public int getDelordreId()
	{
		return delordreId;
	}

	public void setDelordreId(int delordreId)
	{
		this.delordreId = delordreId;
	}

	public int getAntal()
	{
		return antal;
	}

	public void setAntal(int antal)
	{
		this.antal = antal;
	}

	public double getDelTotal()
	{
		double delTotal = 0;
		if (getProdukt() != null)
		{
			delTotal += getProdukt().getPris() * getAntal();
		}
		else if (getService() != null)
		{
			delTotal += getService().getPris() * getAntal();
			if (esList != null)
			{
				for (EkstraService es : getEkstraServiceList())
				{
					delTotal += es.getPris();
				}
			}
		}
		return delTotal;
	}

	public Produkt getProdukt()
	{
		return p;
	}

	public void setProdukt(Produkt p)
	{
		this.p = p;
	}

	public Service getService()
	{
		return s;
	}

	public void setService(Service s)
	{
		this.s = s;
	}

	public ArrayList<EkstraService> getEkstraServiceList()
	{
		return esList;
	}

	public void setEkstraServiceList(ArrayList<EkstraService> esList)
	{
		this.esList = esList;
	}

	public void addEkstraService(EkstraService es)
	{
		System.out.println(es.getBeskrivelse());
		esList.add(es);
	}

	public void removeEkstraService(EkstraService es)
	{
		esList.remove(es);
	}

	public void updateEkstraService(int index, EkstraService es)
	{
		esList.set(index, es);
	}

	public int getEkstraServiceIndex(EkstraService es)
	{
		return esList.indexOf(es);
	}
}
